/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { PCX }  from "./pcx.js";

let uint8 = new Uint8Array([10,5,1,8,0,0,0,0,103,3,179,1,72,0,72,0,15,15,15,14,14,14,13,13,13,12,12,12,11,11,11,10,10,10,9,9,9,8,8,8,7,7,7,6,6,6,5,5,5,4,4,4,3,3,3,2,2,2,1,1,1,0,0,0,0,3,104,3,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,255,99,255,99,255,99,255,99,255,99,255,99,229,99,89,105,193,228,193,242,194,234,193,242,193,228,105,89,221,99,92,102,184,193,195,194,189,193,195,184,102,92,221,99,92,102,184,193,195,209,189,186,190,193,233,193,237,206,234,193,235,193,233,193,226,193,224,255,225,206,225,193,227,193,223,191,187,194,189,187,191,193,223,193,227,209,225,193,227,193,223,191,187,221,189,193,195,184,102,92,255,99,255,99,255,99,197,99,149,255,157,255,157,255,157,255,157,255,157,255,157,229,157,155,158,188,193,192,194,190,193,192,188,158,155,223,157,198,151,225,157,211,151,147,153,188,193,193,206,190,193,192,188,161,158,255,159,206,159,160,159,151,150,194,151,150,151,159,160,209,159,160,159,151,150,223,151,255,157,255,157,255,157,199,157,175,255,184,255,184,255,184,255,184,255,184,255,184,229,184,186,182,149,144,194,147,144,149,182,186,221,184,185,184,176,175,194,176,175,176,184,185,221,184,185,184,176,175,209,176,177,175,148,144,206,147,146,148,166,168,255,167,206,167,166,167,176,177,194,176,177,176,167,166,209,167,166,167,176,177,221,176,175,176,184,185,255,184,255,184,255,184,197,184,255,104,255,104,255,104,255,104,255,104,255,104,230,104,93,111,193,248,196,255,193,248,111,93,218,104,105,104,95,87,99,191,193,202,194,196,193,202,191,108,97,207,104,103,95,204,94,88,99,191,193,202,209,196,193,193,193,198,193,245,193,250,206,247,193,248,193,246,193,237,193,235,226,236,235,237,193,239,193,235,193,199,193,193,194,197,193,193,193,199,193,235,193,239,209,237,193,239,193,235,193,199,193,193,206,197,193,196,193,197,205,196,193,202,191,102,91,214,97,231,104,201,97,255,104,253,104,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,165,163,167,193,199,193,205,194,202,193,205,193,200,167,162,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,163,156,196,155,157,195,165,195,164,195,165,195,164,195,165,195,164,207,163,156,210,155,152,158,193,197,193,202,206,199,193,201,193,197,168,164,226,166,235,168,169,168,158,157,194,158,157,158,168,169,209,168,169,168,158,157,206,158,159,158,157,205,155,157,165,166,214,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,201,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,195,165,195,164,165,255,194,25]) 
let pcxDecoder = new PCX(uint8.buffer);
let runtime = 20000;

function test1() {
	let arr = new Array(10)
	let len = arr.length
	let start = Date.now()
	for (let i = 0; i < runtime; i++) {
		arr[i % len] = new PCX(uint8.buffer);
	}
	let end = Date.now()
	print("pcx_new_PCX: " + (end - start) + ' ms')
	for (let i = 0; i < 10; i++) {
		if (arr[i] == null) {
			print("test1 fail")
		}
	}
}

function test2() {
	let arr = new Array(10)
	let len = arr.length
	let start = Date.now()
	for (let i = 0; i < 10; i++) {
		arr[i % len] = pcxDecoder.decode(); 
	}
	let end = Date.now()
	print("pcx_pcxDecoder: " + (end - start)  + ' ms')
	for (let i = 0; i < 10; i++) {
		if (arr[i] == null) {
			print("test2 fail")
		}
	}
}
test1()
test2()